﻿using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Discovery;

namespace SsoaFramework.Service
{
    public class StandardizedServiceHost : ServiceHost 
    {
        public StandardizedServiceHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses) { }

        protected override void ApplyConfiguration()
        {
            this.Description.Behaviors.Add(new ServiceMetadataBehavior() {HttpGetEnabled = true});
            this.AddServiceEndpoint(
                typeof (IMetadataExchange),
                MetadataExchangeBindings.CreateMexHttpBinding(),
                "mex");

            ServiceDiscoveryBehavior serviceDiscovery = new ServiceDiscoveryBehavior();
            serviceDiscovery.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());
            this.Description.Behaviors.Add(serviceDiscovery);
            this.AddServiceEndpoint(new UdpDiscoveryEndpoint());
            base.ApplyConfiguration();
        }
    }
}
